package com.zf.yichat.controller.carbon;

import com.github.pagehelper.PageHelper;
import com.zf.yichat.controller.BaseController;
import com.zf.yichat.model.StLowCarbonKnowledge;
import com.zf.yichat.service.StCarbonService;
import com.zf.yichat.utils.response.FsResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 汇林低碳
 */
@Controller
@RequestMapping("carbon")
@Slf4j
public class StCarbonController extends BaseController {

    @Autowired
    private StCarbonService stCarbonService;


    /*******************页面访问开始********************************/

    /**
     * 知识列表
     * @return
     */
    @RequestMapping("/knowledge/index")
    public String userLevelIndex() {
        return "carbon/knowledge/index";
    }

    /**
     * 新增知识
     * @return
     */
    @RequestMapping("/knowledge/add")
    public String userLevelAdd() {
        return "carbon/knowledge/save";
    }

    /**
     * 编辑知识
     * @return
     */
    @RequestMapping("/knowledge/edit")
    public String userLevelEdit(Long id) {
        StLowCarbonKnowledge knowledge = stCarbonService.selectKnowledgeById(id);
        getRequest().setAttribute("knowledge", knowledge);
        return "carbon/knowledge/save";
    }

    /*******************页面访问结束********************************/


    /**
     * 查询知识列表
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/knowledge/list")
    @ResponseBody
    public FsResponse knowledgeList(Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        return stCarbonService.selectKnowledgeList();
    };

    /**
     * 新增知识列表
     * @return
     */
    @RequestMapping("/knowledge/saveKnowledge")
    @ResponseBody
    public FsResponse saveKnowledge(StLowCarbonKnowledge knowledge) {
        return stCarbonService.saveKnowledge(knowledge);
    };

    /**
     * 新增知识列表
     * @return
     */
    @RequestMapping("/knowledge/delete")
    @ResponseBody
    public FsResponse deleteKnowledge(Integer id) {
        return stCarbonService.deleteKnowledge(id);
    };

    /**
     * 浇水次数-后台增加任务
     * @return
     */
    @RequestMapping("/plantTree/addNumbers")
    @ResponseBody
    public FsResponse addNumbers(Long userId, Integer num) {
        return stCarbonService.addNumbers(userId, num);
    };

}
